﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EPiBoost.Core.Helpers
{
	public static class CommaSeparatedStringHelper
	{
		public static string Concatenate(IEnumerable<string> values)
		{
			StringBuilder concatenated = new StringBuilder();
			foreach (string value in values)
			{
				concatenated.Append(value);
				concatenated.Append(",");
			}
			if (concatenated.Length > 0)
				concatenated = concatenated.Remove(concatenated.Length - 1, 1);

			return concatenated.ToString();
		}

		public static List<string> Parse(string values)
		{
			var result = new List<string>();

			if (string.IsNullOrEmpty(values))
				return result;
			
			var splitByComma = values.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);

			foreach (var value in splitByComma)
			{
				if (!string.IsNullOrEmpty(value.Trim()))
					result.Add(value.Trim());
			}

			return result;
		}
	}
}
